//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#include <libpub.h>

extern "C" {
void udelay(unsigned long us);
void msleep(unsigned long ms);
}

void udelay(unsigned long us)
{
#if 0
    unsigned long i;
    unsigned long va = 0;

    for(i = 0; i < us * 70000; i++)
        va++;
#else

    unsigned long __T = OSCR0;
    const unsigned long __E = us * 3;// approx 3 ticks per uS

    while(OSCR0 - __T < __E) ;

#endif
}

void msleep(unsigned long ms)
{
    return udelay(ms * 1000);
}


int Do_Delay(char *param)
{
    TOUT(1, 1, printf("timer [%s]\n", param));
    unsigned long s = 1;
    if (*param ) {
        Bo_ParseInteger(param, &s);
    }
    printf("Delay %ds\n", s);
    msleep(s*1000);
    return 0;
}

DECL_MAINCMD(Do_Delay, "delay {second} -- ",  "Wait a moment\n");
